package fizzbuzz

import (
	"strconv"
	"strings"
)

const containsNumThree = "3"
const containsNumFive = "5"
const containsNumSeven = "7"

const fizzSymbol = "Fizz"
const buzzSymbol = "Buzz"
const whizzSymbol = "Whizz"

func play(num int) string {
	var result string

	result = processMultiplyNumComposition(num)

	if contains(num, containsNumThree) {
		result = fizzSymbol
	}

	if contains(num, containsNumFive) && (divisibleByThree(num) || contains(num, containsNumThree)) {
		result = deleteIndicatedSymbol(num, fizzSymbol)
	}

	if contains(num, containsNumSeven) && (divisibleByFive(num) || contains(num, containsNumFive)) {
		result = deleteIndicatedSymbol(num, buzzSymbol)
	}

	if len(result) == 0 {
		result = strconv.Itoa(num)
	}

	return result
}

func deleteIndicatedSymbol(num int, symbol string) string {
	var result string
	result = processMultiplyNumComposition(num)
	if strings.ContainsAny(result, symbol) {
		result = strings.Replace(result, symbol, "", -1)
	}
	return result
}

func contains(num int, containsNum string) bool {
	return strings.Contains(strconv.Itoa(num), containsNum)
}

func processMultiplyNumComposition(num int) string {
	var result string
	if divisibleByThree(num) {
		result += fizzSymbol
	}
	if divisibleByFive(num) {
		result += buzzSymbol
	}
	if divisibleBySeven(num) {
		result += whizzSymbol
	}
	return result
}

func divisibleBySeven(num int) bool {
	return num%7 == 0
}

func divisibleByFive(num int) bool {
	return num%5 == 0
}

func divisibleByThree(num int) bool {
	return num%3 == 0
}
